package office.action.finance;

import java.util.List;
import office.action.finance.form.NoteForm;
import office.service.finance.INoteService;
import platform.common.action.BaseAction;

public class NoteAction extends BaseAction{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private INoteService noteService;
	private NoteForm objctForm;
	private String id;
	private List<NoteForm> wrapperList;
	private String proKey;
	
	/**
	 * 获取岗位异动列表
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public String getListNote()throws Exception{
		objctForm = new NoteForm();
		objctForm.setEntryUserId(getUserId());
		objctForm.setCheckRole(getUserRoleName());
		objctForm.setDeptId(getUserDepartmentId());
		objctForm.setCompanyId(getUserCompanyId());
		//根据用户获取数据列表(查看内容为：自己提交的和需要审批的数据)
		wrapperList = noteService.noteList(objctForm);
		return "showList";
	}
	
	/**
	 * 初始化可用操作
	 * @return
	 * @throws Exception
	 */
	public String gotoEditXml()throws Exception{
		objctForm = noteService.getById(id);
		return "editXml";
	}
	
	/**
	 * 跳转到编辑页面
	 * @return
	 * @throws Exception
	 */
	public String gotoAdd()throws Exception{
//		Map map = (Map)ServletActionContext.getRequest().getSession().getAttribute("user");
//		objctForm.setEntryUserId((String)map.get("userId"));
//		objctForm.setEntryUserName((String)map.get("userCname"));
		return "gotoEdit";
	}
	
	/**
	 * 跳转到编辑页面
	 * @return
	 * @throws Exception
	 */
	public String gotoEdit()throws Exception{
		objctForm = noteService.getById(id);
		return "gotoEdit";
	}
	/**
	 * 添加或编辑数据
	 * @return
	 * @throws Exception
	 */
	public String editData() throws Exception{
		try {
			String userId = getUserId();
			objctForm.setEntryUserId(userId);
			String roleId = getUserRoleName();
			objctForm.setEntryRole(roleId);
			noteService.editNote(objctForm);
			if(null==objctForm.getId() || ("").equals(objctForm.getId())){
				this.getAjaxMessagesJson().setMessage(true, "", "添加票据成功");
			}else{
				this.getAjaxMessagesJson().setMessage(true, "", "编辑票据成功");
			}
			
		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}
	
	/**
	 * 初始化删除
	 * @return
	 * @throws Exception
	 */
	public String gotoDel()throws Exception{
		return "gotoDel";
	}
	/**
	 * 删除
	 * @return
	 * @throws Exception
	 */
	public String delData()throws Exception{
		try {
			noteService.deleteById(id);
			this.getAjaxMessagesJson().setMessage(true, "", "删除成功");
			
		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}
	/**
	 * 确认提交审批页面
	 * @return
	 * @throws Exception
	 */
	public String gotoSubmitCheck()throws Exception{
		return "gotoSubmitCheck";
	}
	/**
	 * 提交审批
	 * @return
	 * @throws Exception
	 */
	public String submitCheck() throws Exception{
		try {
			noteService.submitCheck(id, proKey);
			this.getAjaxMessagesJson().setMessage(true, "", "提交审批成功");
			
		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}

	public INoteService getNoteService() {
		return noteService;
	}

	public void setNoteService(INoteService noteService) {
		this.noteService = noteService;
	}

	public NoteForm getObjctForm() {
		return objctForm;
	}

	public void setObjctForm(NoteForm objctForm) {
		this.objctForm = objctForm;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public List<NoteForm> getWrapperList() {
		return wrapperList;
	}

	public void setWrapperList(List<NoteForm> wrapperList) {
		this.wrapperList = wrapperList;
	}

	public String getProKey() {
		return proKey;
	}

	public void setProKey(String proKey) {
		this.proKey = proKey;
	}
	
}
